package com.self.statistics.schedule;

import com.self.statistics.service.StatisticsDailyService;
import com.self.statistics.utils.DateUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTask {

    private StatisticsDailyService statisticsDailyService;

    //每隔5秒执行程序  秒 分 时 日 月 周 年
    //@Scheduled(cron = "0/5 * * * * ?")
    public void task1(){

        System.out.println("**********task执行了~~~");
    }

    //每天凌晨执行
    @Scheduled(cron = "0 0 1 * * ?")
    public void task(){

        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        statisticsDailyService.registerCount(day);
    }

}
